<?php
/**
 * Created by PhpStorm.
 * User: 勇林
 * Date: 2015/10/2
 * Time: 17:39
 */

namespace app\common\widgets;

use yii\base\Widget;
use Qiniu\Auth;
use Yii;

class MyFileUpload extends Widget{

    public function init(){

        parent::init();

    }

    public  function run(){
        $policy=["persistentOps"=>"vframe/jpg/offset/7/w/480/h/360",
            "persistentNotifyUrl"=>"http://o6sqrcvzn.bkt.clouddn.com"];
        //获取七牛上传所需uptoken，参见http://developer.qiniu.com/docs/v6/sdk/php-sdk.html
        $auth = new Auth(Yii::$app->params['qiniuAccessKey'], Yii::$app->params['qiniuSecretKey']);
        $upToken = $auth->uploadToken(Yii::$app->params['qiniuBucket'],null,3600,$policy);
        $qiniuDomain = Yii::$app->params['qiniuDomain'];
//        var_dump($upToken);die();
        echo $this->render('upload',[
            'qiniuUpToken' => $upToken,
            'qiniuDomain' => $qiniuDomain
        ]);
    }
}